<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<body>
<form id="decorationApplyForm" role="form" method="post" action="onlineRepairControl/save">
    <div class="form-group">
        <label for="repairName">报修人姓名:</label>
        <input type="text" class="form-control" name="repairName" id="repairName" placeholder="请输入姓名"/>
    </div>
    <div class="form-group">
        <label for="repairTel">联系电话:</label>
        <input type="number" class="form-control" name="repairTel" id="repairTel" placeholder="请输入联系电话"/>
    </div>
    <div class="form-group">
        <label for="title">报修标题:</label>
        <input type="text" class="form-control" name="title" id="title" placeholder="请输入标题"/>
    </div>
    <div class="form-group">
        <label for="repairTypeName">报修项目名称:</label>
        <input type="text" class="form-control" name="repairTypeName" id="repairTypeName" placeholder="请输入报修项目名称"/>
    </div>
    <div class="form-group">
         <label for="descInf">备注:</label>
         <input type="text" class="form-control" name="descInf" id="descInf" placeholder="请输入备注"/>
    </div>
    <div class="form-group">
        <label for="repairType">报修类型:</label>
        <select type="text" class="form-control" name="repairType" id="repairType">
        </select>
    </div>
</form>
<script th:inline="javascript">
    <![CDATA[
    $(function () {
        $.post("dict/getType", {type: "REPAIR_TYPE"},
            function (r) {

                for (var i = 0; i < r.data.length; i++) {
                    $("#repairType",window.top.document).append("<option value=" + r.data[i].value + ">" + r.data[i].value + "</option>");
                }
            });

        $('#decorationApplyForm', window.top.document).bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                repairName: {
                    validators: {
                        notEmpty: {
                            message: '报修人不能为空'
                        }
                    }
                },

                repairTel: {
                    validators: {
                        notEmpty: {
                            message: '联系电话不能为空'
                        }
                    }
                },
                title: {
                    validators: {
                        notEmpty: {
                            message: '标题不能为空'
                        }
                    }
                },
                repairTypeName: {
                    validators: {
                        notEmpty: {
                            message: '报修项目名称不能为空'
                        }
                    }
                },
                repairType: {
                    validators: {
                        notEmpty: {
                            message: '标报修类型不能为空'
                        }
                    }
                }
            }
        })

        // 绑定dialog的确定按钮的监听事件
        $("#btnOk", window.top.document).click(function () {
            $("#btnOk", window.top.document).attr("disabled", true);
            // 此段是为防止需要点击两次按钮来实现验证的方法，若不添加此处的放行，那么我们将要点击两次确定按钮才可以提交验证

            var bootstrapValidator = $("#decorationApplyForm", window.top.document).data('bootstrapValidator');
            bootstrapValidator.validate();
            if (bootstrapValidator.isValid()) {
                $.post($("#decorationApplyForm", window.top.document).attr('action'), $("#decorationApplyForm", window.top.document).serialize(), function (e) {
                    if (e.result) {
                        refreshDoQuery();
                        window.Ewin.alert({message: '增加数据成功!'});
                    } else {
                        window.Ewin.alert({message: '增加数据失败!'});
                    }
                    $("#btnOk", window.top.document).attr("disabled", false);
                })
            } else {
                $("#btnOk", window.top.document).attr("disabled", false);
            }
        });

        // 重新刷新当前查询页的数据
        function refreshDoQuery() {
            var iframes = $(window.parent.document).contents().find(".J_iframe");
            for (var i = 0; i < iframes.length; i++) {
                if ($(iframes[i]).css("display") == 'inline') {
                    $('.modal-dialog', window.top.document).parent('div').remove()
                    $('body', window.top.document).find('.modal-backdrop').remove();
                    iframes[i].contentWindow.doQuery();
                    break;
                }
            }
        }
    })
    ]]>
</script>
</body>
</html>